# -*- coding: utf-8 -*-

from flask import request, render_template
from loremipsum import get_sentence, get_paragraph
                       
from ...forms import LentaForm
from ..lenta import _proj 


def add_lenta():
    if request.method == 'GET':
        return render_template('/lenta/lenta/add_lenta.html')
    else:
        form = LentaForm(request.form)
        if form.is_valid():
            ctx = dict(id=100500, namespace='ebanashka')
            ctx.update(_proj(form.data))
            return render_template('/lenta/lenta/add_lenta_ok.html', lenta=ctx)
        return render_template('/lenta/lenta/add_lenta.html', errors=form.errors, lenta=form.data)


def edit_lenta(lenta_id):
    if request.method == 'GET':
        lenta = {
            'id': 100500,
            'namespace': "ebanashka",
            'name': get_sentence(),
            'desc': get_paragraph()
        }
        return render_template('/lenta/lenta/edit_lenta.html', lenta=LentaForm(lenta).htmlize())
    else:
        form = LentaForm(request.form)
        if form.is_valid():
            ctx = dict(id=100500, namespace='ebanashka')
            ctx.update(_proj(form.data))
            return render_template('/lenta/lenta/edit_lenta_ok.html', lenta=ctx)
        return render_template('/lenta/lenta/edit_lenta.html', errors=form.errors, lenta=form.data)


def delete_lenta(lenta_id):
    if request.method == 'GET':
        lenta = {
            'id': 100500,
            'namespace': "ebanashka",
            'name': get_sentence(),
            'desc': get_paragraph()
        }
        return render_template('/lenta/lenta/delete_lenta.html', lenta=lenta)
    else:
        return render_template('/lenta/lenta/delete_lenta_ok.html')

    
def info(lenta_id, namespace):
    lenta = {
        'id': 100500,
        'namespace': "ebanashka",
        'name': get_sentence(),
        'desc': get_paragraph()
    }
    return render_template('/lenta/lenta/lenta_info.html', lenta=lenta)
